/*
** client.c for minitalk in /home/deluxe/Projets_Epi/minitalk
** 
** Made by Deluxe
** Login   <deluxe@epitech.net>
** 
** Started on  Mon Nov 12 14:56:33 2012 Deluxe
** Last update Sat Nov 17 17:00:12 2012 Deluxe
*/

#include "client.h"

int		start_client(int pid, char *mes)
{
  int		c;
  int		i;

  c = 0;
  i = 0;
  while (c < 8)
    {
      if ((int)mes[i] % 2 == 1)
	{
	  kill(pid, SIGUSR1);
	  (int)mes[i] = (int)mes[i] >> 1;
	  usleep(10);
	  i++;
	}
      else if ((int)mes[i] % 2 == 0)
	{
	  kill(pid, SIGUSR2);
	  (int)mes[i] = (int)mes[i] >> 1;
	  usleep(10);	  
	  i++;
	}
      else
	my_putstr("The client don't understand the request\n Goodbye!\n");
      c++;
    }
  return (0);
}

int		main(int ac, char **av)
{
  int		i;

  i = 0;
  if (ac > 3)
    {
      my_putstr("Too Many arguments, ");
      my_putstr("Usage : ./client [SERV_PID] [STRING]\n");
    }
  else if (ac < 3)
    {
      my_putstr("Too Few arguments, ");
      my_putstr("Usage : ./client [SERV_PID] [STRING]\n");
    }
  else
    start_client(my_getnbr(av[1]), av[2]);
}
